package com.tangyuan.video.controller;

import com.tangyuan.aspect.AutoLog;
import com.tangyuan.common.result.Result;
import com.tangyuan.dto.VideoCommentDto;
import com.tangyuan.model.User;
import com.tangyuan.video.service.VideoCommentService;
import com.tangyuan.video.service.VideoService;
import com.xxl.job.core.handler.annotation.XxlJob;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

@RestController
@RequestMapping("/video")
public class VideoCommentController {

    @Autowired
    VideoCommentService videoCommentService;
    @Autowired
    VideoService videoService;

    //添加评论
    @PostMapping("/comment/save")
    public Result saveVideoComment(@RequestHeader("Authorization") String token,
                                   @RequestBody @Valid VideoCommentDto videoCommentDto) {
        return videoCommentService.saveVideoComment(videoCommentDto,token);
    }

    //增添回复评论
    @PostMapping("/replycomment/save")
    public Result saveReplyComment(@RequestHeader("Authorization") String token,
                                   @RequestBody @Valid VideoCommentDto videoCommentDto) {
        return videoCommentService.saveReplyComment(videoCommentDto,token);
    }

    //查询评论(根据视频id查 分页)
    @GetMapping("/comment/query")
    public Result selectCommentByVideoId(
            @RequestHeader("userId") Long userId,
            @RequestParam(value = "videoId") Long videoId,
            @RequestParam(value = "pageSize") Integer pageSize,
            @RequestParam(value = "pageNum") Integer pageNum) {
        return videoCommentService.selectCommentByVideoId(videoId, pageSize, pageNum,userId);
    }

    //查询回复评论(根据评论id查 分页)
    @GetMapping("/replaycomment/query")
    public Result selectReplayCommentByCommentId(@RequestParam(value = "videoId") Long videoId,
                                                 @RequestParam(value = "pageSize") Integer pageSize,
                                                 @RequestParam(value = "pageNum") Integer pageNum) {
        return videoCommentService.selectReplayCommentByCommentId(videoId, pageSize, pageNum);
    }

    //点赞评论
    @AutoLog(value = "点赞评论")
    @GetMapping("/comment/addthump")
    public Result addCommentThumpById(@RequestHeader("userId") Long userId,@RequestParam(value = "commentId") Long commentId) {
        return videoCommentService.addCommentThumpById(commentId,userId);
    }

    //取消点赞评论
    @GetMapping("/comment/removethump")
    public Result removeCommentThumpById(@RequestHeader("userId") Long userId,@RequestParam(value = "commentId") Long commentId) {
        return videoCommentService.removeCommentThumpById(commentId,userId);
    }
    //评论不喜欢
    @GetMapping("/comment/disLike")
    public Result disLike(@RequestHeader("userId") Long userId,@RequestParam(value = "commentId") Long commentId) {
        return videoCommentService.disLike(commentId,userId);
    }
    //移除不喜欢
    @GetMapping("/comment/removedisLike")
    public Result removeDisLike(@RequestHeader("userId") Long userId,@RequestParam(value = "commentId") Long commentId) {
        return videoCommentService.removeDisLike(commentId,userId);
    }
}
